import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Scanner;

class Person implements Cloneable{
    public String name;
    public int age;

    @Override
    protected Object clone() throws CloneNotSupportedException,ArithmeticException {
        return super.clone();
    }
}

class Log {
    private String userName;//用户名
    private String passWord;//密码

    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getPassWord() {
        return passWord;
    }
    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }
    public void LoginInfo(String userName, String passWord) {
        //继承RuntimeException的时候比一定需要声明异常
        if (!this.userName.equals(userName)) {
            throw new UserNameException("用户名异常......");
        }
        if (!this.passWord.equals(passWord)) {
            throw new PassWordException("密码异常.......");
        }
    }
//   public void LoginInfo(String userName, String passWord)
//         throws UserNameException,PassWordException {//继承Exception的时候必须声明
//        if (!this.userName.equals(userName)) {
//            throw new UserNameException("用户名异常......");
//        }
//        if (!this.passWord.equals(passWord)) {
//            throw new PassWordException("密码异常.......");
//        }
//    }
}
public class Test {
    public static void main(String[] args) {
        //自定义登录异常
        Log log = new Log();
        log.setUserName("lisi");
        log.setPassWord("123456");
        try {
            log.LoginInfo("lisi","123456");
        }catch (UserNameException e) {
            e.printStackTrace();
        }catch (PassWordException e) {
            e.printStackTrace();
        }

    }
    public static void gettset() {
        int[] arr = {1,2,3,4,5};
        System.out.println(arr[10]);
    }
    public static void main18(String[] args) {
        gettset();
    }
    public static int get() {
        try {
            return 10;
        }catch (InputMismatchException e) {
            e.printStackTrace();
        }finally {
            return 20;
        }
    }
    public static void main17(String[] args) {
        System.out.println(get());
    }
    public static int getData() {
        try (Scanner scanner = new Scanner(System.in)){
            int data = scanner.nextInt();
            return data;
        }catch (InputMismatchException e) {//输入的如果不是整数就出现异常
            e.printStackTrace();
        }finally {
            System.out.println("fianlly被执行了");

        }
        System.out.println("try-catch-finally之后代码");
//        Scanner scanner = new Scanner(System.in);
//        try {
//            int data = scanner.nextInt();
//            return data;
//        }catch (InputMismatchException e) {//输入的如果不是整数就出现异常
//            e.printStackTrace();
//        }finally {
//            System.out.println("fianlly被执行了");
//            if (scanner != null) {
//                scanner.close();
//            }
//        }
//        System.out.println("try-catch-finally之后代码");
//        if (scanner != null) {
//            scanner.close();//我们输入后就要将其释放。
//        }
        return 0;
    }
    public static void main16(String[] args) {
        int data = getData();
        System.out.println(data);
    }
    public static void main15(String[] args) {
        int[] array = {1,2,3,4};
        try {
            System.out.println(array[5]);
        }catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("处理了ArrayIndexOutOfBoundsException异常");
            e.printStackTrace();
        }catch (NullPointerException e) {
            System.out.println("处理了NullPointerException异常");
            e.printStackTrace();
        }finally {
            System.out.println("finally被执行了");//不管是否出现异常，finally都会被执行
        }
        System.out.println("程序正常");
    }
    public static void main14(String[] args) {
        int[] array = {1,2,3,4};
        try {
            System.out.println(array[6]);//数组越界
            array = null;//置空
            System.out.println(array.length);//使用空指针求长多会出现错误
        }catch (NullPointerException e) {//会报错
            System.out.println("处理了NullPointerException的异常");
            e.printStackTrace();//打印错误的信息
        }catch (Exception e) {//数组越界异常
            System.out.println("处理了Exception的异常");
            e.printStackTrace();//打印错误的信息
        }
        System.out.println("程序正常了，可以执行");



//        int[] array = {1,2,3,4};
//        try {
//            System.out.println(array[6]);//数组越界
//            array = null;//置空
//            System.out.println(array.length);//使用空指针求长多会出现错误
//        }catch (Exception e) {//数组越界异常
//            System.out.println("处理了Exception的异常");
//            e.printStackTrace();//打印错误的信息
//        }catch (NullPointerException e) {//会报错
//            System.out.println("处理了NullPointerException的异常");
//            e.printStackTrace();//打印错误的信息
//        }
//        System.out.println("程序正常了，可以执行");
    }
    public static void main13(String[] args) {
        int[] array = {1,2,3,4};
        try {
            System.out.println(array[6]);//数组越界
            array = null;//置空
            System.out.println(array.length);//使用空指针求长多会出现错误
        }catch (ArrayIndexOutOfBoundsException | NullPointerException e) {//数组越界异常
            System.out.println("处理了ArrayIndexOutOfBoundsException | NullPointerException 的异常");
            e.printStackTrace();//打印错误的信息
        }
        System.out.println("程序正常了，可以执行");
    }
    public static void main12(String[] args) {
        int[] array = {1,2,3,4};
        try {
            System.out.println(array[6]);//数组越界
            array = null;//置空
            System.out.println(array.length);//使用空指针求长多会出现错误
        }catch (ArrayIndexOutOfBoundsException e) {//数组越界异常
            System.out.println("处理了ArrayIndexOutOfBoundsException的异常");
            e.printStackTrace();//打印错误的信息
        }catch (NullPointerException e) {//空指针异常
            System.out.println("处理了NullPointerException的异常");
            e.printStackTrace();
        }
        System.out.println("程序正常了，可以执行");
    }
    public static void funcException(int a) throws CloneNotSupportedException {
        if (a == 0) {
            throw new CloneNotSupportedException();
        }
    }
    public static void main11(String[] args) {
        //int a = 0;
        int a = 2;
        try {
            funcException(a);
            System.out.println("abcdef");
        }catch (CloneNotSupportedException e) {
            System.out.println("这个异常被处理了");
        }
        System.out.println("程序正常，执行代码");
    }

    public static void OpenFile() throws IOException, FileNotFoundException {

    }
    public static void main10(String[] args) throws IOException{
        OpenFile();
    }

    public static void testException(int a) {
        if (a == 0) {
            //算数异常
            throw new ArithmeticException("a == 0");
            //System.out.println("avcde");
        }
    }

    public static void main8(String[] args) {
        int a = 0;
        testException(a);
        System.out.println(10 / a);
    }
    public static void Wechat2() {
//        try {
//            //输入账号和密码
//            //输入验证码
//        }catch (账号密码异常) {
//            //处理账号密码的异常
//        }catch (验证码异常) {
//            //处理验证码异常
//        }
    }

    public static void main7(String[] args) {
        Wechat2();
    }
    public static void Wechat1() {
        //比如说，当我们在电脑上登陆微信的时候呢
        boolean ret = false;
        ret = true;//如果正确输入账号密码返回 true
        if(!ret) {
            //处理找好密码的异常
            return;
        }
        ret = true;//这是确认验证码，如果正确返回 true
        if(!ret) {
            //处理验证码的异常
            return;
        }
        //.......
    }

    public static void main6(String[] args) {
        Wechat1();
    }

//    public static void main(String[] args) {
//        //不是异常，这只是代码编写的问题
//        int a = 10
//    }
    //编译时异常/受查异常
    public static void main5(String[] args) throws CloneNotSupportedException{
        Person person = new Person();
        Person person1 = (Person) person.clone();
    }

    //Error异常
    public static void func(){
        func();
    }
    public static void main4(String[] args) {
        func();
    }
    public static void main3(String[] args) {
        //空指针异常
        int[] array = null;
        System.out.println(array.length);
    }

    public static void main2(String[] args) {
        //数组越界异常
        System.out.println("abcd");
        int[] array = {1,2,3,4,5,6,7};
        System.out.println(array[8]);
        System.out.println("defer");
    }

    public static void main1(String[] args) {
        //算数异常
        System.out.println(10 / 0);
        //ArithmeticException
        //当有异常的时候，这个不能执行
        System.out.println("abcd");
    }
}
